package com.itboye.textileexpres.top;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.content.Entity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.textileexpes.adapter.PagerAdapter;
import com.itboye.textileexpes.adapter.ScrollTabsAdapter;
import com.itboye.textileexpes.beans.ForresterBeans;
import com.itboye.textileexpes.presenter.CategoryPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseActivity;
import com.itboye.textileexpres.base.ResultEntity;
import com.itboye.textileexpres.widget.ScrollTabView;

public class LuntanDaeataActivity extends BaseActivity implements Observer,OnClickListener{
	FrameLayout in;
	private ScrollTabView tabs;
	private ScrollTabsAdapter tabsAdapter;
	private ViewPager viewpager;
	protected List<ForresterBeans> arrayListForm;
	ForresterBeans beans;
	String subforum;
	CategoryPresenter presenter;
	String fid;
	/**
	 * includTop
	 */
	private ImageView back,img_other;
	private TextView title;
	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_collection;
	}

	@Override
	public void onMyCreate() {
		title.setText("全部类目");
		presenter=new CategoryPresenter(this);
		arrayListForm=new ArrayList<ForresterBeans>();
		beans=new ForresterBeans();
		presenter.getInfo(beans);
	}
	@SuppressWarnings("deprecation")
	void initTabs() {
		FragmentGoodsSearch f1 = null;
		viewpager = (ViewPager) findViewById(R.id.viewpager);
		PagerAdapter pagerAdapter = new PagerAdapter(
				getSupportFragmentManager());
		ArrayList<Integer> arrayList = new ArrayList<Integer>();
		tabsAdapter = new ScrollTabsAdapter(this, arrayList);
		
//		for (int i = 1; i <= arrayListForm.size(); i++) {
//			arrayList.add(R.drawable.tab + i);
//			tabsAdapter.add(arrayListForm.get(i-1).getName());//.get(i - 1).getPropName());
//			f1 = new FragmentGoodsSearch(getIntent().getStringExtra("title"),
//					arrayListForm.get(i - 1).getPropId());
//			pagerAdapter.addFragment(f1);
//		}
		viewpager.setAdapter(pagerAdapter);
		viewpager.setCurrentItem(0);
		
		

		tabs.setViewPager(viewpager);
		tabs.setAdapter(tabsAdapter);
	}

	@SuppressWarnings({ "unchecked", "static-access", "unused" })
	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		
		ResultEntity entity = super.handlerError(data);
		System.out.println(">>>>>>>>>>>>>>>>>>>>>"+entity.getData());
		if(entity!=null){
			if(entity.getEventType()==presenter.category_success){
				arrayListForm=(List<ForresterBeans>) entity.getData();
				System.out.println(">>>>>>>>>>>>>>>>>>>>>"+entity.getData());
				String ffid = arrayListForm.get(0).getPropId();
				initTabs();
			}
		}
		
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			this.finish();
			break;

		default:
			break;
		}
	}

}
